import { GetUserInAPI } from "@/request/api"

export default {
    namespaced: true,
    state: {
        //购物车数量
        cartTotal: 6,
        userInfo: {
            //头像
            headImg: require("../../assets/img/userImg.f8bbec5e.png"),
            //名称
            nickName: "游客1",
            //积分
            coin: "---"
        }
    },
    mutations: {
        changeUserInfo(state, payload) {
            state.cartTotal = payload.cartTotal
            state.userInfo = payload.userInfo
        },
        initUserInfo(state) {
            state.cartTotal = 0;
            state.userInfo = {
                headImg: require("../../assets/img/userImg.f8bbec5e.png"),
                nickName: "游客1",
                coin: "---"
            }
        }
    },
    actions: {
        async asyncChangeUserInfo({ commit }) {
            let res = await GetUserInAPI()
            console.log("Vuex用户信息", res);
            commit("changeUserInfo", res.data)
        }
    }
}